/**
 * @param {string} s
 * @return {number}
 */
var myAtoi = function (s) {
  let str = "+-.0123456789";
  s = s.trim();
  let temp = "";
  for (let i = 0; i < s.length; i++) {
    if (temp && !"0123456789".includes(s[i])) {
      break;
    }
    temp += s[i];
  }
  console.log(temp);
  let newNum = Number(temp || 0);
  if (isNaN(newNum)) {
    return 0;
  }

  if (newNum > Math.pow(2, 31) - 1) {
    return Math.pow(2, 31) - 1;
  }
  if (newNum < -Math.pow(2, 31)) {
    return -Math.pow(2, 31);
  }

  return newNum;
};
// var s = "   .800-7+huji";
var s = "   .1";
let result = myAtoi(s);
console.log(result);
